/*******************************************************************************
 * This file is part of the EEG-database project
 * 
 *   ==========================================
 *  
 *   Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/)
 *  
 *  ***********************************************************************************************************************
 *  
 *   Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
 *   the License. You may obtain a copy of the License at
 *  
 *       http://www.apache.org/licenses/LICENSE-2.0
 *  
 *   Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 *   an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 *   specific language governing permissions and limitations under the License.
 *  
 *  ***********************************************************************************************************************
 *  
 *   ArticleComment.java, 2013/10/02 00:01 Jakub Rinkes
  ******************************************************************************/
package cz.zcu.kiv.eegdatabase.data.pojo;

// Generated 2.12.2013 0:56:28 by Hibernate Tools 3.4.0.CR1

import cz.zcu.kiv.eegdatabase.data.annotation.SolrField;
import cz.zcu.kiv.eegdatabase.data.annotation.SolrId;
import cz.zcu.kiv.eegdatabase.logic.indexing.IndexField;

import javax.persistence.*;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Transient;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;

/**
 * ArticleComment generated by hbm2java
 */
@Entity
@Table(name = "ARTICLES_COMMENTS")
public class ArticleComment implements Serializable {

	@SolrId
	private int commentId;
	private Article article;
	private ArticleComment parent;
	private Set<ArticleComment> children = new HashSet<ArticleComment>(0);
	private Timestamp time;
	private Person person;
	@SolrField(name = IndexField.TEXT)
	private String text;
	
	
	private boolean userMemberOfGroup; // changes dynamically from app
    private boolean userIsOwnerOrAdmin; // changes dynamically from app

	@Transient
	public boolean isUserMemberOfGroup() {
		return userMemberOfGroup;
	}

	public void setUserMemberOfGroup(boolean userMemberOfGroup) {
		this.userMemberOfGroup = userMemberOfGroup;
	}

	@Transient
	public boolean isUserIsOwnerOrAdmin() {
		return userIsOwnerOrAdmin;
	}

	public void setUserIsOwnerOrAdmin(boolean userIsOwnerOrAdmin) {
		this.userIsOwnerOrAdmin = userIsOwnerOrAdmin;
	}


		

	public ArticleComment() {
	}

	public ArticleComment(Person person) {
		this.person = person;
	}

	public ArticleComment(Article article, ArticleComment parent,
			Set<ArticleComment> children, Timestamp time, Person person,
			String text) {
		this.article = article;
		this.parent = parent;
		this.children = children;
		this.time = time;
		this.person = person;
		this.text = text;
	}

	@GenericGenerator(name = "generator", strategy = "increment")
	@Id
	@GeneratedValue(generator = "generator")
	@Column(name = "COMMENT_ID", nullable = false, precision = 22, scale = 0)
	public int getCommentId() {
		return this.commentId;
	}

	public void setCommentId(int commentId) {
		this.commentId = commentId;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "ARTICLE_ID")
	public Article getArticle() {
		return this.article;
	}

	public void setArticle(Article article) {
		this.article = article;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "PARENT_ID")
	public ArticleComment getParent() {
		return this.parent;
	}

	public void setParent(ArticleComment parent) {
		this.parent = parent;
	}

	@OneToMany(fetch = FetchType.EAGER, mappedBy = "parent")
	@OrderBy("time ASC")
	public Set<ArticleComment> getChildren() {
		return this.children;
	}

	public void setChildren(Set<ArticleComment> children) {
		this.children = children;
	}

	@Column(name = "TIME", length = 7)
	public Timestamp getTime() {
		return this.time;
	}

	public void setTime(Timestamp time) {
		this.time = time;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "PERSON_ID", nullable = false)
	public Person getPerson() {
		return this.person;
	}

	public void setPerson(Person person) {
		this.person = person;
	}

	@Lob
	@Type(type = "org.hibernate.type.TextType")
	@Column(name = "TEXT")
	public String getText() {
		return this.text;
	}

	public void setText(String text) {
		this.text = text;
	}

}
